import Vue from 'vue'
import Vuex from 'vuex'

import {
  sysNewsContentsQuery,
  sysNewsContentsDelete,
  sysNewsContentsAdd,
  sysNewsContentsUpdate,
  sysNewsContentsDeleteBatch,
} from '@/api/admin/collect/sysNewsContents'

Vue.use(Vuex)

const state = {
  // taskRow: {},
}

const getters = {}

const actions = {
  //文章内容增删改查
  async queryNewsContents({ commit }, listQuery) {
    let res = await sysNewsContentsQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async deleteNewsContents({ commit }, row) {
    let res = await sysNewsContentsDelete(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async addNewsContents({ commit }, data) {
    let res = await sysNewsContentsAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async updateNewsContents({ commit }, data) {
    let res = await sysNewsContentsUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async deleteBatchNewsContents({ commit }, data) {
    let res = await sysNewsContentsDeleteBatch(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {
  // SET_TASKROW: (state, d) => {
  //   state.taskRow = Object.assign(state.taskRow, d)
  // },
  // CLEAR_TASKROW: (state) => {
  //   state.taskRow = {}
  // },
}

export default {
  state,
  getters,
  actions,
  mutations,
}
